{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3D Keypoint Visualizatino in 3D view\n",
    "\n",
    "In this example, we visualize 3D body/face/hands in 3D space"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import json\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "plt.rcParams['image.interpolation'] = 'nearest'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Setup paths\n",
    "data_path = '../'\n",
    "seq_name = '171204_pose1_sample'\n",
    "\n",
    "hd_skel_json_path = data_path+seq_name+'/hdPose3d_stage1_coco19/'\n",
    "hd_face_json_path = data_path+seq_name+'/hdFace3d/'\n",
    "hd_hand_json_path = data_path+seq_name+'/hdHand3d/'\n",
    "#hd_img_path = data_path+seq_name+'/hdImgs/'\n",
    "\n",
    "colors = plt.cm.hsv(np.linspace(0, 1, 10)).tolist()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load camera calibration parameters (for visualizing cameras)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Load camera calibration parameters (for visualizing cameras)\n",
    "with open(data_path+seq_name+'/calibration_{0}.json'.format(seq_name)) as cfile:\n",
    "    calib = json.load(cfile)\n",
    "\n",
    "# Cameras are identified by a tuple of (panel#,node#)\n",
    "cameras = {(cam['panel'],cam['node']):cam for cam in calib['cameras']}\n",
    "\n",
    "# Convert data into numpy arrays for convenience\n",
    "for k,cam in cameras.iteritems():    \n",
    "    cam['K'] = np.matrix(cam['K'])\n",
    "    cam['distCoef'] = np.array(cam['distCoef'])\n",
    "    cam['R'] = np.matrix(cam['R'])\n",
    "    cam['t'] = np.array(cam['t']).reshape((3,1))\n",
    "\n",
    "    \n",
    "# Choose only HD cameras for visualization\n",
    "hd_cam_idx = zip([0] * 30,range(0,30))\n",
    "hd_cameras = [cameras[cam].copy() for cam in hd_cam_idx]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Select Image Frame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Select HD Image index\n",
    "hd_idx = 400"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWQAAADuCAYAAAAOR30qAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3XtcVHXeB/DPmRnmAgqKgiFjKBeR\ni1jewtbaar0k+ZCXdFmt9HHdV95Sa9PH1q1X7qPZ9jyv7fLoS+uxzNYneelaUV6wbLfNVZFEkQRF\nCAwkUJT7MNdzfs8fOCMoowPOuQzzfb9evpTDML/fOQ6f+c3vnPP9cYwxEEIIkZ9K7g4QQghpQ4FM\nCCEKQYFMCCEKQYFMCCEKQYFMCCEKQYFMCCEKQYFMCCEKQYFMCCEKQYFMCCEKoeni4+m2PkII6TrO\nkwfRCJkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSC\nApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQ\nQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQQhSC\nApkQQhSCApkQQhSCApkQQhSCApkQQhSCApkQIrtVq1Zh2LBhSElJwfTp09HQ0OD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zh06BCz2+2MMcZWr17NVq9ezRhjrLCwkKWkpDCLxcLKyspYdHQ0czgczOFwsOjo\naPbjjz8yq9XKUlJSWGFhYZfbLSoqYufPn2e//OUv2ffff+/aLna77YnxnDf75z//yfLy8lhSUpJr\n26pVq9jGjRsZY4xt3LjRdcz379/PHn/8cSYIAjt+/DgbO3Zst9v9+eefWV5eHmOMsaamJhYXF8cK\nCwslaZvcFY8ylkbIPdSkSZNct2+npqbi0qVLAICsrCxkZGRAp9NhyJAhiI2NRW5urtcqcSUkJCA+\nPv6W7WK3254UVcUefvhhhIaGdtiWlZWFefPmAQDmzZuHzz//3LX92WefBcdxSE1NRUNDA6qrq7vV\nbkREBEaOHAkA6N27NxISElBVVSVJ20R8FMh+4MMPP8SUKVMAuK+4JXYlLinblauq2OXLlxEREQGg\nLTivXLkian8uXryI06dP44EHHpC8bSIOujHEh02YMAE1NTW3bN+wYYOrstuGDRug0Wgwd+5cAO4r\nbjnrbdy8vbvt3swb7XrKXVtyEaM/LS0tmDlzJt5++20EBwdL2jYRDwWyDzt8+PBtv79jxw7s27cP\n33zzjeuX8HYVtzytxHWndjvjjXa90ZaYBgwYgOrqakRERKC6uhrh4eGi9Mdut2PmzJmYO3cuZsyY\nIWnbRFw0ZdFDZWdn489//jO++OILBAYGuranp6cjMzMTVqsV5eXlKCkpwdixYztU4rLZbMjMzER6\nerrX+iNlu2Lvizvp6enYsWMHgLY3Q+enhfT0dHz88cdgjCEnJwchISGu6YWuYozht7/9LRISEvDi\niy9K2jaRgKdn/xhdZeFTYmJimNFoZCNGjGAjRoxgzz33nOt769evZ9HR0Wzo0KHswIEDru379+9n\ncXFxLDo6mq1fv75b7X766acsMjKSabVaFh4eziZNmiRJuzcT4znby8jIYPfccw/TaDQsMjKSbdu2\njV29epU99thjLDY2lj322GPs2rVrjDHGBEFgS5YsYdHR0Sw5ObnD1SdddeTIEQaADR8+3PV/u3//\nfknaJnfFo4ylO/UIIUR8dKceIYT4EgpkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghR\nCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApk\nQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghR\nCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCApkQghRCE0X\nH8+J0gtCCCE0QiaEEKWgQCaEEIWgQCaEEIWgQCaEEIWgQCaEEIWgQCaEEIWgQCaEEIWgQCaEEIWg\nQCaEEIWgQCaEEIX4f0P4iPCB5npfAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from mpl_toolkits.mplot3d import Axes3D\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.add_subplot(111, projection='3d')\n",
    "ax.view_init(elev = -90, azim=-90)\n",
    "#ax.set_xlabel('X Label')\n",
    "ax.set_ylabel('Y Label')\n",
    "#ax.set_zlabel('Z Label')\n",
    "ax.axis('equal')\n",
    "\n",
    "# Draw selected camera subset in blue\n",
    "for cam in hd_cameras:\n",
    "    cc = (-cam['R'].transpose()*cam['t'])\n",
    "    ax.scatter(cc[0], cc[1], cc[2], '.', color=[0,0,1])\n",
    "    \n",
    "'''\n",
    "## Visualize 3D Body\n",
    "'''\n",
    "# Edges between joints in the body skeleton\n",
    "body_edges = np.array([[1,2],[1,4],[4,5],[5,6],[1,3],[3,7],[7,8],[8,9],[3,13],[13,14],[14,15],[1,10],[10,11],[11,12]])-1\n",
    "\n",
    "try:\n",
    "    # Load the json file with this frame's skeletons\n",
    "    skel_json_fname = hd_skel_json_path+'body3DScene_{0:08d}.json'.format(hd_idx)\n",
    "    with open(skel_json_fname) as dfile:\n",
    "        bframe = json.load(dfile)\n",
    "\n",
    "    # Bodies\n",
    "    for ids in xrange(len(bframe['bodies'])):\n",
    "        body = bframe['bodies'][ids]\n",
    "        skel = np.array(body['joints19']).reshape((-1,4)).transpose()\n",
    "\n",
    "        for edge in body_edges:\n",
    "            ax.plot(skel[0,edge], skel[1,edge], skel[2,edge], color=colors[body['id']])\n",
    "            \n",
    "except IOError as e:\n",
    "    print('Error reading {0}\\n'.format(skel_json_fname)+e.strerror)\n",
    "    \n",
    "'''\n",
    "## Visualize 3D Face\n",
    "'''\n",
    "# Face keypoint orders follow Openpose keypoint output\n",
    "# https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/output.md\n",
    "# Face outline points (0-16) are unstable\n",
    "face_edges = np.array([ #[0,1],[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[11,12],[12,13],[14,15],[15,16], #outline (ignored)\n",
    "                [17,18],[18,19],[19,20],[20,21], #right eyebrow\n",
    "                [22,23],[23,24],[24,25],[25,26], #left eyebrow\n",
    "                [27,28],[28,29],[29,30],   #nose upper part\n",
    "                [31,32],[32,33],[33,34],[34,35], #nose lower part\n",
    "                [36,37],[37,38],[38,39],[39,40],[40,41],[41,36], #right eye\n",
    "                [42,43],[43,44],[44,45],[45,46],[46,47],[47,42], #left eye\n",
    "                [48,49],[49,50],[50,51],[51,52],[52,53],[53,54],[54,55],[55,56],[56,57],[57,58],[58,59],[59,48], #Lip outline\n",
    "                [60,61],[61,62],[62,63],[63,64],[64,65],[65,66],[66,67],[67,60] #Lip inner line \n",
    "                ])\n",
    "\n",
    "# Load the json file with this frame's face\n",
    "try:\n",
    "    face_json_fname = hd_face_json_path+'faceRecon3D_hd{0:08d}.json'.format(hd_idx)\n",
    "    with open(face_json_fname) as dfile:\n",
    "        fframe = json.load(dfile)\n",
    "\n",
    "    # Cycle through all detected faces\n",
    "    for face in fframe['people']:\n",
    "        \n",
    "        # 3D Face has 70 3D joints, stored as an array [x1,y1,z1,x2,y2,z2,...]\n",
    "        face3d = np.array(face['face70']['landmarks']).reshape((-1,3)).transpose()\n",
    "\n",
    "        # Plot edges for each bone\n",
    "        for edge in face_edges:\n",
    "            ax.plot(face3d[0,edge], face3d[1,edge], face3d[2,edge], color=colors[face['id']])\n",
    "\n",
    "except IOError as e:\n",
    "    print('Error reading {0}\\n'.format(face_json_fname)+e.strerror)\n",
    "\n",
    "\n",
    "'''\n",
    "## Visualize 3D Hand\n",
    "'''\n",
    "# Joint orders follow Openpose keypoint output\n",
    "# https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/output.md\n",
    "hand_edges = np.array([[0,1],[1,2],[2,3],[3,4],\n",
    "                [0,5],[5,6],[6,7],[7,8],\n",
    "                [0,9],[9,10],[10,11],[11,12],\n",
    "                [0,13],[13,14],[14,15],[15,16],\n",
    "                [0,17],[17,18],[18,19],[19,20]])\n",
    "try:\n",
    "    # Load the json file with this frame's face\n",
    "    hand_json_fname = hd_hand_json_path+'handRecon3D_hd{0:08d}.json'.format(hd_idx)\n",
    "    with open(hand_json_fname) as dfile:\n",
    "        hframe = json.load(dfile)\n",
    "\n",
    "    # Cycle through all detected hands\n",
    "    for hand in hframe['people']:\n",
    "        \n",
    "        # 3D hands, right_hand and left_hand, have 21 3D joints, stored as an array [x1,y1,z1,x2,y2,z2,...]\n",
    "\n",
    "        '''\n",
    "        # Right hand\n",
    "        '''\n",
    "        hand3d = np.array(hand['right_hand']['landmarks']).reshape((-1,3)).transpose()\n",
    "\n",
    "        # Plot edges for each bone\n",
    "        for edge in hand_edges:\n",
    "            ax.plot(hand3d[0,edge], hand3d[1,edge], hand3d[2,edge], color=colors[hand['id']])\n",
    "\n",
    "        '''\n",
    "        # Left hand\n",
    "        '''\n",
    "        hand3d = np.array(hand['left_hand']['landmarks']).reshape((-1,3)).transpose()\n",
    "\n",
    "        # Plot edges for each bone\n",
    "        for edge in hand_edges:\n",
    "            ax.plot(hand3d[0,edge], hand3d[1,edge], hand3d[2,edge], color=colors[hand['id']])\n",
    "\n",
    "except IOError as e:\n",
    "    print('Error reading {0}\\n'.format(hand_json_fname)+e.strerror)\n",
    "\n",
    "\n",
    "    \n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
